/* -----------------------------------------------------------------------------
 * PROJECT    : lwf_handlers
 * FILE       : TableTests.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Feb 8, 2011  mycodetalks			       Created
 */
package net.lwf.pdf.util;
/**
 * Class description goes here
 */
import java.awt.Color;
import java.util.List;



import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;

public class TableTests {
/*
	 public static final String DIRECTORY = "/eclipse/workspace/pdf/demofiles/results/part1/chapter04";
	 public static final String FILE_NAME = "testtables.pdf";
	 public static final String RESOURCE = "resources/lwf/%s.jpg";
	 
	 public void displayFonts(Document document) throws DocumentException {
		 
		 Paragraph para = new Paragraph("Font Demos................... Normal Fonts");
		 para.setAlignment(Element.ALIGN_CENTER);
		 document.add(para);
		 
		//-------------------------------------------------------------------------- Normal Fonts
		 para = new Paragraph("This is the default font (Family: Times Roman; Size: 20; Weight: Normal; Color: Black", FontUtil.getDisplayFont());
		 document.add(para);
		 
		 document.add(new Phrase("\n__________________________________________________________________________"));
		 para = new Paragraph("This is the font for (Family: Specified font 'Courier'; Default Size: 20; Default Weight: Normal; Default Color: Black", FontUtil.getDisplayFont(FontFactory.COURIER));
		 document.add(para);
		 
		 document.add(new Phrase("\n_________________________________________________________________________"));
		 para = new Paragraph("This is the font for (Default Family: Times Roman; Specified Size: 26; Default Weight: Normal; Default Color: Black", FontUtil.getDisplayFont(26));
		 document.add(para);
		 
		 document.add(new Phrase("\n__________________________________________________________________________"));
		 para = new Paragraph("This is the font for (Specified Family: Helvetica; Specified Size: 24; Default Weight: Normal; Default Color: Black", FontUtil.getDisplayFont(FontFactory.HELVETICA, 24));
		 document.add(para);
		 
		 document.newPage();
		 document.add(new Phrase("\n__________________________________________________________________________"));
		 para = new Paragraph("This is the font for (Specified Family: Times; Specified Size: 28; Specified Weight: Bold; Default Color: Black", FontUtil.getDisplayFont(FontFactory.TIMES, 28, Font.BOLD));
		 document.add(para);
		 
		 document.add(new Phrase("\n__________________________________________________________________________"));
		 para = new Paragraph("This is the custom font for (Specified Family: Helvetica; Specified Size: 30; Specified Weight: Bold; Default Color: Red", FontUtil.getDisplayFont(FontFactory.COURIER_OBLIQUE, 30, Font.NORMAL, BaseColor.RED));
		 document.add(para);
		 
		 //-------------------------------------------------------------------------- Bolded Fonts
		 
		 para = new Paragraph("\nFont Demos................... Bolded Fonts");
		 para.setAlignment(Element.ALIGN_CENTER);
		 document.add(para);
		 
		 para = new Paragraph("This is the default bolded font (Family: Times Roman; Size: 20; Weight: Bold; Color: Black", FontUtil.getBoldedDisplayFont());
		 document.add(para);
		 
		 document.add(new Phrase("\n_________________________________________________________________________"));
		 para = new Paragraph("This is the bolded font (Specified Font Family: Helvetica Oblique; Default Size: 20; Default Weight: Bold; Default Color: Black", FontUtil.getBoldedDisplayFont(FontFactory.HELVETICA_OBLIQUE));
		 document.add(para);
		 
		 document.add(new Phrase("\n_________________________________________________________________________"));
		 para = new Paragraph("This is the bolded font (Specified Font Family: Courier Oblique; Default Size: 20; Default Weight: Bold; Default Color: Black", FontUtil.getBoldedDisplayFont(20));
		 document.add(para);
		 
		 document.add(new Phrase("\n__________________________________________________________________________"));
		 para = new Paragraph("This is the bolded font (Specified Font Family: Times Roman; Default Size: 20; Default Weight: Bold; Default Color: Black", FontUtil.getBoldedDisplayFont(FontFactory.TIMES_ROMAN, 24));
		 document.add(para);
		 
		 document.add(new Phrase("\n__________________________________________________________________________"));
		 this.getFontTable(document);
		 document.newPage();
	 }
	 
	 private void getFontTable(Document document) throws DocumentException {
	        PdfPTable table = new PdfPTable(3);

	        // the cell object
	        PdfPCell cell;
	        
	        //Header Cells
	        cell = new PdfPCell(new Phrase(" Column 1", FontUtil.getCellHeaderFont()));
	        cell.setBackgroundColor(new BaseColor(0xee, 0xee, 0xee));
	        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
	        table.addCell(cell);
	        
	        cell = new PdfPCell(new Phrase(" Column 2", FontUtil.getCellHeaderFont()));
	        cell.setBackgroundColor(new BaseColor(0xcc, 0xcc, 0xcc));
	        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
	        table.addCell(cell);
	        
	        cell = new PdfPCell(new Phrase(" Column 3", FontUtil.getCellHeaderFont()));
	        table.addCell(cell);
	        
	        //Row one
	        cell = new PdfPCell(new Phrase("cell 11", FontUtil.getCellFont()));
	        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	        table.addCell(cell);
	        
	        cell = new PdfPCell(new Phrase("cell 12", FontUtil.getCellFont()));
	        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
	        table.addCell(cell);
	        
	        cell = new PdfPCell(new Phrase("cell 13", FontUtil.getCellFont()));
	        table.addCell(cell);

	        table.completeRow();
	        //Row two
	        cell = new PdfPCell(new Phrase("cell 21", FontUtil.getCellFont()));
	        table.addCell(cell);
	        
	        cell = new PdfPCell(new Phrase("cell 22", FontUtil.getCellFont()));
	        table.addCell(cell);
	        
	        cell = new PdfPCell(new Phrase("cell 33", FontUtil.getCellFont()));
	        table.addCell(cell);
	        table.completeRow();
	        document.add(table);
	 }

	public void getContent(Document document) throws DocumentException {
		
		this.displayFonts(document);
		
		
        
        //------------------------------------------------------------------------- a simple table
        Paragraph p = new Paragraph(" ");
        document.add(p);
        p = new Paragraph("A Simple Table Demo..........");
        p.setAlignment(Element.ALIGN_CENTER);
        document.add(p);
        p = new Paragraph(" ");
        document.add(p);
        
        
        PdfPTable table = new PdfPTable(3);

        // the cell object
        PdfPCell cell;
        
        //Row one
        cell = new PdfPCell(new Phrase("cell 11"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        
        cell = new PdfPCell(new Phrase("cell 12"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);
        
        cell = new PdfPCell(new Phrase("cell 13"));
        table.addCell(cell);

        table.completeRow();
        //Row two
        cell = new PdfPCell(new Phrase("cell 21"));
        table.addCell(cell);
        
        cell = new PdfPCell(new Phrase("cell 22"));
        table.addCell(cell);
        
        cell = new PdfPCell(new Phrase("cell 33"));
        table.addCell(cell);
        table.completeRow();
        document.add(table);
       
       //---------------------------------------------------------- Demo 1 for row span and column span
        p = new Paragraph(" ");
        document.add(p);
        p = new Paragraph("Demo for row span and column span..........");
        p.setAlignment(Element.ALIGN_CENTER);
        document.add(p);
        p = new Paragraph(" ");
        document.add(p);
    	// a table with three columns
        table = new PdfPTable(3);

        // we add a cell with colspan 3
        cell = new PdfPCell(new Phrase("Cell with colspan 3"));
        cell.setColspan(3);
        table.addCell(cell);
        // now we add a cell with rowspan 2
        cell = new PdfPCell(new Phrase("Cell with rowspan 2"));
        cell.setRowspan(2);
        table.addCell(cell);
        // we add the four remaining cells with addCell()
        table.addCell("row 2; cell 2");
        table.addCell("row 2; cell 3");
        table.addCell("row 3; cell 2");
        table.addCell("row 3; cell 3");
        
        table.completeRow();
        document.add(table);
        
        table = new PdfPTable(2);
        table.setWidthPercentage(20.0f);
        table.setSpacingBefore(20);
        table.addCell(" ");
        cell = new PdfPCell(new Phrase("Data1"));
        cell.setBorder(0);
        table.addCell(cell);
        table.addCell("sign");
        cell = new PdfPCell(new Phrase("Data2"));
        cell.setBorder(0);
        table.addCell(cell);        
        cell = new PdfPCell(new Phrase(" "));
        cell.setColspan(2);
        cell.setBorderWidth(.5f);
        cell.setBorderColor(BaseColor.RED);
        table.addCell(cell);
        table.completeRow();
        document.add(table);
      //---------------------------------------------------------- Demo 2 for row span and column span
        table = new PdfPTable(3);
        table.setSpacingBefore(20);
        table.getDefaultCell().setPadding(5);

        cell = new PdfPCell(new Phrase("header"));
        cell.setPadding(5);
        cell.setColspan(3);
        table.addCell(cell);
        table.setHeaderRows(1);
        cell = new PdfPCell(new Phrase("example cell with rowspan 2 and red border"));
        cell.setPadding(5);
        cell.setRowspan(2);
        cell.setBorderColor(new BaseColor(new Color(255, 0, 0)));
        table.addCell(cell);
        table.addCell("1.1");
        table.addCell("2.1");
        table.addCell("1.2");
        table.addCell("2.2");
        cell = new PdfPCell(new Phrase("align center"));
        cell.setPadding(5);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("big cell"));
        cell.setPadding(5);
        cell.setRowspan(2);
        cell.setColspan(2);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("align right"));
        cell.setPadding(5);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell);
        document.add(table);
        
        //---------------------------------------------------------- Demo for setting borders and colors
        
        table = new PdfPTable(3);
        table.setSpacingBefore(20);
        
        //Row one
        cell = new PdfPCell(new Phrase("11"));
        cell.setBorderColor(new BaseColor(new Color(255, 0, 0)));
        cell.setBorderWidth(2);
        table.addCell(cell);
        
        cell = new PdfPCell(new Phrase("cell 12"));
        table.addCell(cell);
        
        cell = new PdfPCell(new Phrase("13"));
        cell.setBorderColorTop(new BaseColor(new Color(98, 36, 0)));
        cell.setBorderColorRight(new BaseColor(new Color(200, 180, 0)));
        table.addCell(cell);

        table.completeRow();
        //Row two
        cell = new PdfPCell(new Phrase("cell 21"));
        table.addCell(cell);
        
        cell = new PdfPCell(new Phrase("cell 22"));
        cell.setBorderWidth(0);
        table.addCell(cell);
        
        cell = new PdfPCell(new Phrase("cell 33"));
        table.addCell(cell);
        table.completeRow();
        document.add(table);
        
        //---------------------------------------------------------- Demo for text rotations and border colots
        table = new PdfPTable(4);
        table.setSpacingBefore(20);
        table.setWidths(new int[]{ 1, 3, 3, 3 });
        table.setWidthPercentage(100);
        
        // row 1, cell 1
        cell = new PdfPCell(new Phrase("COLOR"));
        cell.setRotation(90);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
        // row 1, cell 2
        cell = new PdfPCell(new Phrase("red / no borders"));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setBackgroundColor(BaseColor.RED);
        table.addCell(cell);
        // row 1, cell 3
        cell = new PdfPCell(new Phrase("green / black bottom border"));
        cell.setBorder(Rectangle.BOTTOM);
        cell.setBorderColorBottom(BaseColor.BLACK);
        cell.setBorderWidthBottom(10f);
        cell.setBackgroundColor(BaseColor.GREEN);
        table.addCell(cell);
        // row 1, cell 4
        cell = new PdfPCell(new Phrase(
                "cyan / blue top border + padding"));
        cell.setBorder(Rectangle.TOP);
        cell.setUseBorderPadding(true);
        cell.setBorderWidthTop(5f);
        cell.setBorderColorTop(BaseColor.BLUE);
        cell.setBackgroundColor(BaseColor.CYAN);
        table.addCell(cell);
        // row 2, cell 1
        cell = new PdfPCell(new Phrase("GRAY"));
        cell.setRotation(90);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);
        // row 2, cell 2
        cell = new PdfPCell(new Phrase("0.6"));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setGrayFill(0.6f);
        table.addCell(cell);
        // row 2, cell 3
        cell = new PdfPCell(new Phrase("0.75"));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setGrayFill(0.75f);
        table.addCell(cell);
        // row 2, cell 4
        cell = new PdfPCell(new Phrase("0.9"));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setGrayFill(0.9f);
        table.addCell(cell);
        // row 3, cell 1
        cell = new PdfPCell(new Phrase("BORDERS"));
        cell.setRotation(90);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        table.addCell(cell);
        // row 3, cell 2
        cell = new PdfPCell(new Phrase("different borders"));
        cell.setBorderWidthLeft(16f);
        cell.setBorderWidthBottom(12f);
        cell.setBorderWidthRight(8f);
        cell.setBorderWidthTop(4f);
        cell.setBorderColorLeft(BaseColor.RED);
        cell.setBorderColorBottom(BaseColor.ORANGE);
        cell.setBorderColorRight(BaseColor.YELLOW);
        cell.setBorderColorTop(BaseColor.GREEN);
        table.addCell(cell);
        // row 3, cell 3
        cell = new PdfPCell(new Phrase("with correct padding"));
        cell.setUseBorderPadding(true);
        cell.setBorderWidthLeft(16f);
        cell.setBorderWidthBottom(12f);
        cell.setBorderWidthRight(8f);
        cell.setBorderWidthTop(4f);
        cell.setBorderColorLeft(BaseColor.RED);
        cell.setBorderColorBottom(BaseColor.ORANGE);
        cell.setBorderColorRight(BaseColor.YELLOW);
        cell.setBorderColorTop(BaseColor.GREEN);
        table.addCell(cell);
        // row 3, cell 4
        cell = new PdfPCell(new Phrase("red border"));
        cell.setBorderWidth(8f);
        cell.setBorderColor(BaseColor.RED);
        table.addCell(cell);
        document.add(table);
        
        //------------------ Widths
        table = new PdfPTable(3);
        table.setSpacingBefore(20);
        table.setWidths(new int[]{3, 15, 2});
        table.setWidthPercentage(100);
        // cell 1: location and time
        //cell.setBorder(PdfPCell.NO_BORDER);
        cell = new PdfPCell();
        cell.setBackgroundColor(BaseColor.WHITE);
        cell.setUseAscender(true);
        cell.setUseDescender(true);
        cell.addElement(new Paragraph("a cell"));
        table.addCell(cell);
        // cell 2: English and original title 
        cell = new PdfPCell();
        cell.addElement(new Paragraph("a cell"));
        //cell.setBorder(PdfPCell.NO_BORDER);
        cell.setUseAscender(true);
        cell.setUseDescender(true);
        table.addCell(cell);
        // cell 3 duration
        cell = new PdfPCell();
        //cell.setBorder(PdfPCell.NO_BORDER);
        cell.setBackgroundColor(BaseColor.WHITE);
        cell.setUseAscender(true);
        cell.setUseDescender(true);
        p = new Paragraph("a cell");
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        table.addCell(cell);
        document.add(table);

        /*
        //New tables
        
        p = new Paragraph(" ");
        document.add(p);
        
        PdfPTable table1 = new PdfPTable(3);
        
        //Header
        CellProperties cellprops = new CellProperties();
        cellprops.setBorderBottomWidth(3.0f);
        cellprops.setBorderLeftWidth(5.0f);
        cellprops.setBorderTopColor(new BaseColor(0xcc, 0xcc, 0xcc));
        //cellprops.setBorder(5);
        cellprops.setCellBackground(new BaseColor(0x74, 0x71, 0x70));
        cell = PdfPCellUtil.getHeaderCell("Column 1", cellprops);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);
        
        cell = PdfPCellUtil.getHeaderCell("Column 2", cellprops);
        table1.addCell(cell);
        
        cell = PdfPCellUtil.getHeaderCell("Column 2", cellprops);
        table1.addCell(cell);
        
        //Row one
        cell = PdfPCellUtil.getCell(new Phrase("cell 11", FontUtil.getDisplayFont()));
        table1.addCell(cell);
        

        
        cell = PdfPCellUtil.getCell(new Phrase("cell 12", FontUtil.getDisplayFont()));
        table1.addCell(cell);
        
        cell = PdfPCellUtil.getCell(new Phrase("cell 13", FontUtil.getDisplayFont()));
        table1.addCell(cell);

        table1.completeRow();
        //Row two
        cell = new PdfPCell(new Phrase("cell 21"));
        table1.addCell(cell);
        
        cell = new PdfPCell(new Phrase("cell 22"));
        table1.addCell(cell);
        
        Paragraph para = new Paragraph("cell 33 by paragraph");
        para.setAlignment(Element.ALIGN_MIDDLE);
        //cell = new PdfPCell(new Phrase("cell 33"));
        cell = PdfPCellUtil.getCell(para);
        table1.addCell(cell);
        table1.completeRow();
        document.add(table1);
       

	}

	/**
	 * @param args
	 */
/*	public static void main(String[] args) {
		TableTests tpg = new TableTests();
		Document document = tpg.getPortraitDocument(DIRECTORY, FILE_NAME);
		tpg.generate(document);

	}

	@Override
	public int getColumns() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getRows() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<?> getTabularData() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Element processCellData(Object object) {
		// TODO Auto-generated method stub
		return null;
	}*/

}




